package lv.accenture.ex07;

public class TestThreads1 {

  public static void main(String[] args) {
    HelloRunner1 r = new HelloRunner1();
    Thread t1 = new Thread(r, "R1");
    Thread t2 = new Thread(r, "R2");
    Thread t3 = new Thread(r, "R3");
    Thread t4 = new Thread(r, "R4");
    t1.start();
    t2.start();
    t3.start();
    t4.start();
  }
}

class HelloRunner1 implements Runnable {
  int count = 0; 
	
  public void run() {

    while (count < 10000) {

    	synchronized (this) {
          System.out.println("Hello #" + count + " from "
        			+ Thread.currentThread().getName());
        count++;				
      }

		try
		{
		  Thread.sleep(1);
		}
		catch (InterruptedException e)
		{
			System.err.println("Interrupted");
    	}
    }
  }
}